﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SyndicateBusiness.Classes;
using SyndicateDAO.DatabaseObject;

namespace BigLotterySyndicate.Secured.Draws.Controls
{
    public partial class DrawDetails : Base
    {
        public enum Tab
        {
            General = 1,
            Lines = 2,
            AddLine = 3,
            Players = 4,
            AddPlayer = 5,
            AddOldLines = 6,
            AddFreePlayer = 7
        }

        protected Tab SelectedTab
        {
            get
            {
                return (Tab)Utilities.StringToInt(this.Request["Tab"], 1);
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (DesignMode)
                return;

            View activeView = null;

            this.PlaceHolderAddLine.Visible = false;
            this.PlaceHolderAddPlayer.Visible = false;
            this.PlaceHolderAddPlayer.Visible = false;
            this.PlaceHolderAddOldLines.Visible = false;

            switch (this.SelectedTab)
            {
                default:
                case Tab.General:
                    activeView = Tab1;
                    break;
                case Tab.Lines:
                    activeView = Tab2;
                    this.TabLines.Visible = this.CurrentDraw.type == draw.drawType.LOTTO;
                    this.TabLinesEuro.Visible = this.CurrentDraw.type == draw.drawType.EUROMILLIONS;
                    this.TabLinesHealth.Visible = this.CurrentDraw.type == draw.drawType.HEALTHLOTTERY;
                    break;
                case Tab.AddLine:
                    this.PlaceHolderAddLine.Visible = true;
                    activeView = Tab3;

                    this.TabAddLine.Visible = this.CurrentDraw.type == draw.drawType.LOTTO;
                    this.TabAddLineEuro.Visible = this.CurrentDraw.type == draw.drawType.EUROMILLIONS;
                    this.TabAddLineHealth.Visible = this.CurrentDraw.type == draw.drawType.HEALTHLOTTERY;
                    break;

                case Tab.Players:
                    activeView = Tab4;
                    break;
                case Tab.AddPlayer:
                    this.PlaceHolderAddPlayer.Visible = true;
                    activeView = Tab5;
                    break;
                case Tab.AddOldLines:
                    this.PlaceHolderAddOldLines.Visible = true;
                    activeView = Tab6;
                    break;
                case Tab.AddFreePlayer:
                    this.PlaceHolderAddFreePlayer.Visible = true;
                    activeView = Tab7;
                    break;

            }

            if (activeView != null)
            {
                MultiViewDetails.SetActiveView(activeView);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Visible)
                return;


          

            if (CurrentDraw.syndicateId != this.BasePage.LoggedInUser.syndicateId)
                this.BasePage.Redirect("/Secured/Default.aspx?Ns=0");

            this.BasePage.MasterPage.BgType = CurrentDraw.type;

        }

        protected string PrintClassIfSelected(Tab tab, string cssClass)
        {
            return (tab == this.SelectedTab ? cssClass : "");
        }
    }
}